<?php

namespace  Aitels\Foundation\Event;

use Illuminate\Support\Facades\Event;
use  Aitels\Foundation\Annotation\ApplicationAnnotationsContainer;
use  Aitels\Foundation\Annotation\ListeningAnnotation;
use  Aitels\Foundation\Code\ClassAnalyser;

class AnnotationListenerRegister
{
    public function register()
    {
        $listenerAnnotations = ApplicationAnnotationsContainer::getApplicationAnnotations(ListeningAnnotation::NAME);
        foreach ($listenerAnnotations as $classPath => $listenAnnotation) {
            foreach ($listenAnnotation as $methodName => $annotation) {
                $handler = ClassAnalyser::getClassByPath($classPath) . '@' . $methodName;
                Event::listen($annotation, $handler);
            }
        }
    }

}